import time
from pathlib import Path


def list_files_with_pathlib(folder_path):
    try:
        folder = Path(folder_path)
        if not folder.exists():
            print(f"错误：目录 '{folder_path}' 不存在。")
            return []
        if not folder.is_dir():
            print(f"错误：'{folder_path}' 不是一个目录。")
            return []

        # 获取所有文件（不包括子目录）
        files = [file.name for file in folder.iterdir() if file.is_file()]
        return files
    except PermissionError:
        print(f"错误：没有权限访问目录 '{folder_path}'。")
        return []


if __name__ == '__main__':
    print('开始')
    timestamp = int(time.time())
    image_1 = []
    folder_path = "C:\\4\\"
    files = list_files_with_pathlib(folder_path)
    for file_1 in files:
        image_1.append(file_1[0:-8])
    unique_arr = list(set(image_1))
    for aa in unique_arr:
        temp = 0
        for file_1 in files:
            if file_1.startswith(aa):
                temp += 1
        if temp == 1:
            print(aa)

            # import time
            # from pathlib import Path
            #
            #
            # def list_files_with_pathlib(folder_path):
            #     try:
            #         folder = Path(folder_path)
            #         if not folder.exists():
            #             print(f"错误：目录 '{folder_path}' 不存在。")
            #             return []
            #         if not folder.is_dir():
            #             print(f"错误：'{folder_path}' 不是一个目录。")
            #             return []
            #
            #         # 获取所有文件（不包括子目录）
            #         files = [file.name for file in folder.iterdir() if file.is_file()]
            #         return files
            #     except PermissionError:
            #         print(f"错误：没有权限访问目录 '{folder_path}'。")
            #         return []
            #
            #
            # if __name__ == '__main__':
            #     print('开始')
            #     timestamp = int(time.time())
            #     image_1 = []
            #     folder_path = "C:\\4\\"
            #     files = list_files_with_pathlib(folder_path)
            #     for file_1 in files:
            #         print(file_1)
            #         image_1.append(file_1[0:-8])
            #     unique_arr = list(set(image_1))
            #     for aa in unique_arr:
            #         temp = 0
            #         for file_1 in files:
            #             if file_1.startswith(aa):
            #                 bb = int(file_1[-8:-7])
            #                 if bb > temp:
            #                     temp = bb
            #         if temp == 0:
